package cn.dkk.behavior_design.responsibility;

/**
 * @author dkk
 * @date 2022/7/25
 * @desc
 */
public abstract class Handler {

    public static final int NUM_ONE = 1;
    public static final int NUM_THREE = 3;
    public static final int NUM_SEVEN = 7;

    // 可处理请假的区间
    private final int start;
    private final int end;

    private Handler nextHandler;

    public Handler(int start, int end) {
        this.start = start;
        this.end = end;
    }

    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    protected abstract void handleLeave(LeaveRequest leaveRequest);

    public final void submit(LeaveRequest leaveRequest) {
        handleLeave(leaveRequest);
        if (nextHandler!=null && leaveRequest.getNum()>end){
            nextHandler.submit(leaveRequest);
        }else {
            System.out.println("处理完毕");
        }
    }

}
